<?php


namespace app\modules\Admin\models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;

class dianpuapplyModel extends Model
{
    protected $table = 'dianpu_apply';
    protected $primaryKey = 'id';
    protected $appends = ['status_name','pay_status_name'];
    protected $hidden = [];

    protected static array $statuss = [
        -1 => '驳回',
        0  => '未审核',
        1  => '已通过'
    ];

    protected static array $payStatus = [
        -1 => '已退回',
        0 => '未支付',
        1 => '已支付'
    ];
    /**
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public static function getStatusArray()
    {
        return self::$statuss;
    }

    public static function getPayStatusArray()
    {
        return self::$payStatus;
    }

    public function getStatusNameAttribute($value)
    {
        $status_name = '未知';
        $all_status = self::$statuss;
        if(isset($all_status[$this->attributes['status']])){
            $status_name = $all_status[$this->attributes['status']];
        }

        return $status_name;
    }

    public function getPayStatusNameAttribute($value)
    {
        $status_name = '未知';
        $all_status = self::$payStatus;
        if(isset($all_status[$this->attributes['agent_fee_pay_status']])){
            $status_name = $all_status[$this->attributes['agent_fee_pay_status']];
        }

        return $status_name;
    }

    public function dianpu()
    {
        return $this->belongsTo(dianpuModel::class, 'id', 'apply_id');
    }

    public function member()
    {
        return $this->belongsTo(\memberModel::class, 'member_id', 'id')->select(['id', 'phone', 'nickname', 'realname', 'avatar']);
    }
}